<!-- head -->
{include file='public/head' /}
<!-- head -->

<!-- left -->
{include file='public/left' /}
<!-- left -->

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            管理后台
            <small>1.0.0</small>
        </h1>
        <ol class="breadcrumb">
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-sm-12">
                <div class="box box-default">
                    <div class="box-header with-border">
                        <h3 class="box-title">{$webcity.city}--添加优秀顾问</h3>
                    </div>
                    <form class="form-horizontal" id="form" action="{:url('admin/webcity/postinsertconsultant','','')}">
                        <input type="hidden" id="city_id" value="{$webcity.id}">
                        <div class="box-body">
                            <div class="form-group">
                                <label for="name" class="col-sm-2 control-label">姓名</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="name" name="name" placeholder="姓名">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="idcard" class="col-sm-2 control-label">身份证</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="idcard" name="idcard" placeholder="身份证">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="idcard_expire" class="col-sm-2 control-label">身份证有效期</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="idcard_expire" name="idcard_expire" placeholder="身份证有效期">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="phone" class="col-sm-2 control-label">电话</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="phone" name="phone" placeholder="电话">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="job" class="col-sm-2 control-label">公司职务</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="job" name="job" placeholder="公司职务">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="description" class="col-sm-2 control-label">描述</label>
                                <div class="col-sm-10">
                                    <textarea class="form-control" id="description" name="description" placeholder="顾问描述，显示在首页"></textarea>
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="intro" class="col-sm-2 control-label">简介</label>
                                <div class="col-sm-10">
                                    <textarea class="form-control" id="intro" name="intro" placeholder="顾问简介，显示在顾问详情"></textarea>
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="yewu" class="col-sm-2 control-label">业务范围</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="yewu" name="yewu" placeholder="业务范围">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="star" class="col-sm-2 control-label">推荐星级</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="star" name="star" placeholder="推荐星级，填1-5" value="5">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="img" class="col-sm-2 control-label">图片</label>
                                <div class="col-sm-10">
                                    <input type="file" class="form-control" id="img" name="img">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                        </div>
                        <div class="box-footer" style="text-align:right;">
                            <button type="button" class="btn btn-sm btn-default" id="resetForm">清空</button>&nbsp;
                            <button type="button" class="btn btn-sm btn-primary" id="saveForm">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->

<line href="__STATIC__/bootstrap-fileinput/css/fileinput.css" type="text/css" rel="stylesheet" />
<script src="__STATIC__/bootstrap-fileinput/js/fileinput.js" type="text/javascript"></script>
<script src="__STATIC__/bootstrap-fileinput/js/locales/zh.js" type="text/javascript"></script>
<script type="text/javascript">

    var imgName = '';

    $("#img").fileinput({
        language : 'zh',
        showRemove: false,
        showUpload: true,
        showClose: false,
        showPreview: false,
        allowedFileTypes: ['image'],
        allowedFileExtensions : ['jpg', 'jpeg', 'png', 'gif'],
        uploadUrl: '{:url("admin/public/uploadimg","","")}',
        uploadExtraData: {
            'folder': 'consultant',
        },
    });

    $("#img").on("fileuploaded", function (event, data, previewId, index) {
        var result = data.response;
        if (result.status == 1) {
            imgName = result.data;
        } else {
            showAlert('提示', result.info, null);
        }
    });
</script>

<script type="text/javascript">

    $(function(){

        $('#saveForm').click(function(){
            var city_id = $('#city_id').val();

            var name = $.trim($('#name').val());
            if (name == '') {
                $('#name').parents('.form-group').addClass('has-error');
                $('#name').parent().find('.help-block').html('请输入姓名');
                return false;
            }

            var idcard = $.trim($('#idcard').val());
            if (idcard == '') {
                $('#idcard').parents('.form-group').addClass('has-error');
                $('#idcard').parent().find('.help-block').html('请输入身份证');
                return false;
            }

            var idcard_expire = $.trim($('#idcard_expire').val());
            if (idcard_expire == '') {
                $('#idcard_expire').parents('.form-group').addClass('has-error');
                $('#idcard_expire').parent().find('.help-block').html('请输入身份证有效期');
                return false;
            }

            var phone = $.trim($('#phone').val());
            if (phone == '') {
                $('#phone').parents('.form-group').addClass('has-error');
                $('#phone').parent().find('.help-block').html('请输入电话');
                return false;
            }

            var job = $.trim($('#job').val());
            if (job == '') {
                $('#job').parents('.form-group').addClass('has-error');
                $('#job').parent().find('.help-block').html('请输入公司职务');
                return false;
            }

            var description = $.trim($('#description').val());
            if (description == '') {
                $('#description').parents('.form-group').addClass('has-error');
                $('#description').parent().find('.help-block').html('请输入描述');
                return false;
            }

            var intro = $.trim($('#intro').val());
            if (intro == '') {
                $('#intro').parents('.form-group').addClass('has-error');
                $('#intro').parent().find('.help-block').html('请输入简介');
                return false;
            }

            var yewu = $.trim($('#yewu').val());
            if (yewu == '') {
                $('#yewu').parents('.form-group').addClass('has-error');
                $('#yewu').parent().find('.help-block').html('请输入业务范围');
                return false;
            }

            var star = $.trim($('#star').val());
            if (star == '') {
                $('#star').parents('.form-group').addClass('has-error');
                $('#star').parent().find('.help-block').html('请输入推荐星级');
                return false;
            }

            if (imgName == '') {
                $('#img').parents('.form-group').addClass('has-error');
                $('#img').parents('.form-group').find('.help-block').html('请上传图片');
            }

            $.ajax({
                url: $('#form').attr('action'),
                type: 'POST',
                data: {
                    'webcity_id': city_id,
                    'name': name,
                    'idcard': idcard,
                    'idcard_expire': idcard_expire,
                    'phone': phone,
                    'job': job,
                    'description': description,
                    'intro': intro,
                    'yewu': yewu,
                    'star': star,
                    'img': imgName,
                },
                dataType: 'JSON',
                success: function(data) {
                    if (data.status == 1) {
                        window.location.href = "{:url('admin/webcity/consultant',['webcity_id'=>$webcity.id],'')}";
                    } else {
                        showAlert('提示', data.info, null);
                    }
                }
            });
        });

        $('#name').focus(function(){
            if ($('#name').parents('.form-group').hasClass('has-error')) {
                $('#name').parents('.form-group').removeClass('has-error');
                $('#name').parent().find('.help-block').html('');
            }
        });

        $('#idcard').focus(function(){
            if ($('#idcard').parents('.form-group').hasClass('has-error')) {
                $('#idcard').parents('.form-group').removeClass('has-error');
                $('#idcard').parent().find('.help-block').html('');
            }
        });

        $('#idcard_expire').focus(function(){
            if ($('#idcard_expire').parents('.form-group').hasClass('has-error')) {
                $('#idcard_expire').parents('.form-group').removeClass('has-error');
                $('#idcard_expire').parent().find('.help-block').html('');
            }
        });

        $('#phone').focus(function(){
            if ($('#phone').parents('.form-group').hasClass('has-error')) {
                $('#phone').parents('.form-group').removeClass('has-error');
                $('#phone').parent().find('.help-block').html('');
            }
        });

        $('#job').focus(function(){
            if ($('#job').parents('.form-group').hasClass('has-error')) {
                $('#job').parents('.form-group').removeClass('has-error');
                $('#job').parent().find('.help-block').html('');
            }
        });

        $('#description').focus(function(){
            if ($('#description').parents('.form-group').hasClass('has-error')) {
                $('#description').parents('.form-group').removeClass('has-error');
                $('#description').parent().find('.help-block').html('');
            }
        });

        $('#intro').focus(function(){
            if ($('#intro').parents('.form-group').hasClass('has-error')) {
                $('#intro').parents('.form-group').removeClass('has-error');
                $('#intro').parent().find('.help-block').html('');
            }
        });

        $('#yewu').focus(function(){
            if ($('#yewu').parents('.form-group').hasClass('has-error')) {
                $('#yewu').parents('.form-group').removeClass('has-error');
                $('#yewu').parent().find('.help-block').html('');
            }
        });

        $('#star').focus(function(){
            if ($('#star').parents('.form-group').hasClass('has-error')) {
                $('#star').parents('.form-group').removeClass('has-error');
                $('#star').parent().find('.help-block').html('');
            }
        });

        $('#img').focus(function(){
            if ($('#img').parents('.form-group').hasClass('has-error')) {
                $('#img').parents('.form-group').removeClass('has-error');
                $('#img').parents('.form-group').find('.help-block').html('');
                return false;
            }
        });



    });

</script>

<!-- right -->
{include file='public/right' /}
<!-- right -->

<!-- foot -->
{include file='public/foot' /}
<!-- foot -->
